# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(cpp-journey                   # 项目名称
  VERSION 1.0                         # 项目版本（可选）
  LANGUAGES CXX                       # 指定语言（CXX为C++）
)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)           # 设置 C++ 标准为 C++17
set(CMAKE_CXX_STANDARD_REQUIRED ON)  # 要求使用 C++17 标准
set(CMAKE_BUILD_TYPE Release)        # 默认构建类型（Debug/Release）

# 设置可执行文件输出目录
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# 设置库文件输出目录
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

# 添加头文件搜索路径
include_directories(${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
include_directories(${PROJECT_SOURCE_DIR}/src)

# 自动查找 src 目录下的所有源文件
file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")

# 生成静态库
add_library(${PROJECT_NAME}_static STATIC ${SOURCES})
set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

# 生成动态库
add_library(${PROJECT_NAME}_shared SHARED ${SOURCES})
set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

# 添加可执行文件
add_executable(${PROJECT_NAME}_${PROJECT_VERSION} ${SOURCES})

# 链接库到可执行文件
target_link_libraries(${PROJECT_NAME}_${PROJECT_VERSION} PRIVATE ${PROJECT_NAME}_static)

# 处理第三方库（示例）
# if(EXISTS "${PROJECT_SOURCE_DIR}/thirdparty")
#    add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty)
#     target_link_libraries(${PROJECT_NAME} thirdparty_lib) # 假设第三方库名为 thirdparty_lib
# endif()

# 处理单元测试
if(BUILD_TESTS)
    enable_testing()
    add_subdirectory(test)
endif()